import { getDefenceTags, getTagsDetail,addDefence,getDenfenceRows ,getClassPlanTree,getClassPlanInit} from '@/services'
import { makeAutoObservable } from 'mobx'
import { IDefenceTags,IDefenceAddItem , IDefenceRows,IClassPlanTree,ITagsDetail,IGroup} from '@/utils/interface'

class Tags {
    constructor() {
        makeAutoObservable(this)
    }


    // 定义仓库的属性
    defenceTags: IDefenceTags[] = []
    defenceRows:IDefenceRows[]=[]
    classPlanTree:IClassPlanTree[]=[]
    tagsDetail:ITagsDetail[]=[]
    classPlanInit:IGroup[]=[]
    classplan:string[]=[]
    // 定义新增答辩参数
    defenceAddItem: IDefenceAddItem = {
        "classplan":[],
        "defenceAdress": "",
        "defenceAuthorName": "郭老师",
        "defenceClassId": "",
        "defenceCreateTime":"",
        "defenceEndTime": "",
        "defenceId": "",
        "defenceMajorId": "",
        "defencePlanId": "",
        "defenceScore": "",
        "degenceName": "",
        "planName":"",
        "majorList": "",
        "time": []
    }


    // 定义仓库中的方法
    // 获取列表
    async getDefenceTags() {
        let result = await getDefenceTags();
        if (result.data) {
            this.defenceTags = result.data
        }
    }

    
    // 获取表格列表
    async getDenfenceRows(params:IDefenceRows) {
        let {defenceCreateTime,defenceEndTime,defenceId,defenceStatus,degenceName,majorName,planName}=params
        this.defenceRows={...this.defenceRows,defenceCreateTime,defenceEndTime,defenceId,defenceStatus,degenceName,majorName,planName}
        let result=await getDenfenceRows(this.defenceRows)
        if(result.data){
            this.defenceRows=result.data
            return result.data.defenceId
        }
    }

    // 获取班级计划
    async getClassPlanTree(){
        let result=await getClassPlanTree()
        if(result.data){
            this.classPlanTree=result.data
        }
    }

    // 新增答辩
    async addDefence(params:IDefenceAddItem){
        console.log(params)
        let {defenceAdress,defenceMajorId,degenceName,planName,defenceCreateTime,defenceEndTime,time}=params
        this.defenceAddItem={...this.defenceAddItem,defenceMajorId,degenceName,planName,defenceAdress,defenceCreateTime,defenceEndTime,time,classplan:this.classplan};
        let result = await addDefence(this.defenceAddItem)
        console.log(result)
        if(result.data){
            this.defenceAddItem=result.data
            return result.data.defenceId
        }
    }

    // 获取答辩详情
    async getTagsDetail(defenceId:string){
        let result=await getTagsDetail(defenceId)
        console.log(result);
        if(result.data){       
            this.defenceAddItem=result.data
            this.tagsDetail=result.data
        }
    }

    // 获取当前小组详情
    async getClassPlanInit(classPlanid:string){
        let result=await getClassPlanInit(classPlanid)
        if(result.data){
            this.classPlanInit=result.data
        }
    }
    changclassplan(value:string[]){
        this.classplan=value
        
        
    }
    // // 删除列表
    // async deleteDefenceRow(defenceId:string){
    //     let result=await this.deleteDefenceRow(defenceId)
    //     if(result.rows){
    //         this.
    //     }

    // }
}

export default new Tags